package com.tongji.housediy.view.titlewindows
{
	import com.tongji.housediy.events.commonEvent.RotationRelatedEvent;
	import com.tongji.housediy.events.commonEvent.ShowHideTitleWindowEvent;
	import com.tongji.housediy.model.SelectedObjectModel;
	import com.tongji.housediy.utils.ConstVariableInventory;
	import com.tongji.housediy.view.components.RoomFloor;
	
	import flash.events.MouseEvent;
	
	import mx.managers.PopUpManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class FloorColorWindowMediator extends Mediator
	{
		[Inject]
		public var view:FloorColorTitleWindow;
		
		[Inject]
		public var selectedModel:SelectedObjectModel;
		
		override public function onRegister():void
		{
			ConstVariableInventory.isShowColorPicker = false;
			
			mediatorMap.createMediator(view.materialView);
			mediatorMap.createMediator(view.materialView.popupBtn.popUp);
			
			view.okBtn.addEventListener(MouseEvent.CLICK, okBtnClickHandler);
			view.cancelBtn.addEventListener(MouseEvent.CLICK, closeBtnClickHandler);
			view.closeBtn.addEventListener(MouseEvent.CLICK, closeBtnClickHandler);
		}
		
		private function closeBtnClickHandler(event:MouseEvent):void
		{
			PopUpManager.removePopUp(view);
			mediatorMap.removeMediatorByView(view.materialView.popupBtn.popUp);
			mediatorMap.removeMediatorByView(view.materialView);
			mediatorMap.removeMediatorByView(view);
		}
		
		private function okBtnClickHandler(event:MouseEvent):void
		{
			if (view.materialView.tempFloorPicModel)
			{
				(selectedModel.selectedObj as RoomFloor).changeSizeAndColor(view.materialView.tempFloorPicModel, view.materialView.tempFloorMap, view.materialView.tempFloorGoods);
			}
			
			PopUpManager.removePopUp(view);
			mediatorMap.removeMediatorByView(view.materialView.popupBtn.popUp);
			mediatorMap.removeMediatorByView(view.materialView);
			mediatorMap.removeMediatorByView(view);
			
			dispatch(new ShowHideTitleWindowEvent(ShowHideTitleWindowEvent.HIDE_TITLE_WINDOW));
			dispatch(new RotationRelatedEvent(RotationRelatedEvent.HIDE_ROTATION_BTN));
		}
	}
}